/*******************************************************************************
 *
 * File Name:          ForumboardLoader.java
 *
 * Created:            2006-11-3 22:59:44
 *
 * Original Author:    yu.peng
 *
 *------------------------------------------------------------------------------
 * MODIFICATION HISTORY
 *------------------------------------------------------------------------------
 * WHEN                WHO                 WHY
 * 2006-11-3 22:59:44 yu.peng             new
 *------------------------------------------------------------------------------
 *
 ******************************************************************************/
/*******************/
/* PACKAGE SECTION */
/*******************/
package org.njo.webapp.root.listener;

import org.njo.webapp.root.model.activity.ForumActivity;

import javax.servlet.ServletContextListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContext;
import java.util.List;

/**
 * 在webapp启动时加载论坛版块数据.<br>
 *
 * 注意:在维护论坛版块数据的程序中,如果增加,修改或删除了版块数据时,
 *      需要更新保存在ServletContext中的数据.
 *
 * @author yu.peng
 * @version 0.01
 */
public class ForumboardLoader implements ServletContextListener {

    public final static String CONTEXT_FORUMBOARD_KEY = "furumboards";

    /**
     * 在webapp启动时加载论坛版块数据.<br>
     * TODO:完成这个方法,并测试.
     *
     * @param servletContextEvent
     */
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ServletContext context = servletContextEvent.getServletContext();
        ForumActivity forum = new ForumActivity();
        // 左侧菜单数据
        List boards = forum.getBoards();
        context.setAttribute(CONTEXT_FORUMBOARD_KEY, boards);
    }

    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        ServletContext context = servletContextEvent.getServletContext();
        context.removeAttribute(CONTEXT_FORUMBOARD_KEY);
    }

}
